package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop/")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;
    private  final static String key ="SHOP_STATUS";


    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态为：{}",status==1 ? "营业中":"已打烊");
        redisTemplate.opsForValue().set(key,status);
        return Result.success();
    }


    @GetMapping("/{status}")
    public Result<Integer> getStatus(){
        Integer status =(Integer) redisTemplate.opsForValue().get(key);
        log.info("当前店铺状态为：{}",status==1 ? "营业中":"已打烊");
        return Result.success(status);
    }



}
